<template>
  <div id="switchMapControl">
    <img
      v-for="item in imgs"
      @click="imgClick"
      :class="getImgClass(item.type)"
      :src="item.src"
      :alt="item.alt"
      :value="item.type"
      :key="item.type"
    />
  </div>
</template>

<script>
import { vuexStore } from "/js/vuexStore.js";
import { switchMap } from "/js/map2.js";

let vue = new Vue({
  el: "#switchMapControl",
  name: "switchMapControl",
  created() {},
  data() {
    return {
      imgs: [
        {
          src: "images/e-map.png",
          type: 1,
          alt: "电子地图",
        },
        {
          src: "images/image-map.png",
          type: 2,
          alt: "卫星地图",
        },
      ],
    };
  },
  methods: {
    imgClick(e) {
      let type = parseInt(e.target.attributes["value"].value);
      switchMap(type);
    },
    getImgClass(type) {
      let imgMargin = type === 1;

      if (vuexStore.state.mapTileType === type) {
        return { imgCurrent: true, imgMargin: imgMargin };
      } else {
        return { img: true, imgMargin: imgMargin };
      }
    },
  },
  computed: {},
});
</script>

<style>
#switchMapControl {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background-color: transparent;
  width: 135px;
  height: 44px;
  z-index: 1999;
  border: 0;
  text-align: right;
  user-select: none;
}

#switchMapControl .imgCurrent {
  width: 56px;
  height: 40px;
  border: solid 2px #0197a6;
  border-radius: 4px;
}

#switchMapControl .img {
  width: 56px;
  height: 40px;
  border: solid 2px #999999;
  border-radius: 4px;
  opacity: 0.8;
}

#switchMapControl .imgMargin {
  margin-right: 10px;
}
</style>
